export function useSubmit({
  subject = '',
  message = '',
  createApikey = null,
  updateApiKey = null,
  onCreated = () => { },
  onUpdated = (old, data) => { return Object.assign(old, data) },
}) {
  const currentRow = ref<any>({})
  const isEdit = computed(() => !!currentRow.value?.uuid)
  const msg = computed(() => message || `${subject}${isEdit.value ? '修改' : '添加'}`)
  const apikey = computed(() => isEdit.value ? updateApiKey : createApikey)
  const hooks = {
    onSuccess: () => { },
  }
  const { bvisible, bsubmit } = useBaseSubmit({
    msg,
    apikey,
    hooks,
  })
  function display(row) {
    currentRow.value = row
    bvisible.value = true
  }

  async function submit(newForm) {
    hooks.onSuccess = isEdit.value ? onUpdated.bind({}, currentRow.value, newForm) : onCreated
    bsubmit(newForm)
  }
  return {
    isEdit,
    currentRow,
    ovisible: bvisible,
    display,
    submit,
  }
}
